package com.jt.www.biz.user_wxb.controller;

import com.jt.www.annotations.AddHeader;
import com.jt.www.biz.user_wxb.service.WeChatAppLoginService;
import com.jt.www.model.reps.GenericDataResponse;
import com.jt.www.model.wx.UserInfoVO;
import com.jt.www.model.wx.WxParamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/")
public class WxController {

    @Autowired
    WeChatAppLoginService weChatAppLoginService;

    @AddHeader
    @PostMapping("wx_user")
    public ResponseEntity<?> getUserInfo(@RequestBody WxParamBean wxParamBean) {
        try {
            UserInfoVO vo = weChatAppLoginService.getUserInfo(wxParamBean);
            if (vo != null) {
                return GenericDataResponse.okWithData(vo);
            } else {
                return GenericDataResponse.errorWithMsg("用户不存在");
            }
        } catch (Exception e) {
            return GenericDataResponse.errorWithMsg(e.getMessage());
        }
    }

    @AddHeader
    @GetMapping("judge_user/{code}/{clientType}")
    public ResponseEntity<?> judgeUserInfo(@PathVariable("code") String code, @PathVariable("clientType") String clientType) {
        try {
            return GenericDataResponse.okWithData(weChatAppLoginService.judgeUserExists(code, clientType));
        } catch (Exception e) {
            return GenericDataResponse.errorWithMsg(e.getMessage());

        }
    }
}
